<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateWechatFans extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('wechat_fans',['engine'=>'InnoDB'])->setComment('微信-粉丝');
        $table->addColumn(Column::string('appid',50)->setNullable()->setComment('公众号APPID'));
        $table->addColumn(Column::string('unionid',100)->setNullable()->setComment('粉丝unionid'));
        $table->addColumn(Column::string('openid',100)->setNullable()->setComment('粉丝openid'));
        $table->addColumn(Column::string('tagid_list',100)->setNullable()->setComment('粉丝标签id'));
        $table->addColumn(Column::tinyInteger('is_black')->setDefault(0)->setComment('是否为黑名单状态'));
        $table->addColumn(Column::tinyInteger('subscribe')->setDefault(0)->setComment('关注状态(0未关注,1已关注)'));
        $table->addColumn(Column::string('nickname',200)->setNullable()->setComment('用户昵称'));
        $table->addColumn(Column::tinyInteger('sex')->setDefault(0)->setComment('用户性别(1男性,2女性,0未知)'));
        $table->addColumn(Column::string('country',50)->setNullable()->setComment('用户所在国家'));
        $table->addColumn(Column::string('province',50)->setNullable()->setComment('用户所在省份'));
        $table->addColumn(Column::string('city',50)->setNullable()->setComment('用户所在城市'));
        $table->addColumn(Column::string('language',50)->setNullable()->setComment('用户的语言(zh_CN)'));
        $table->addColumn(Column::string('headimgurl',500)->setNullable()->setComment('用户头像'));
        $table->addColumn(Column::bigInteger('subscribe_time')->setDefault(0)->setComment('关注时间'));
        $table->addColumn(Column::dateTime('subscribe_at')->setNullable()->setComment('关注时间'));
        $table->addColumn(Column::string('remark',50)->setNullable()->setComment('备注'));
        $table->addColumn(Column::string('subscribe_scene',200)->setNullable()->setComment('扫码关注场景'));
        $table->addColumn(Column::string('qr_scene',100)->setNullable()->setComment('二维码场景值'));
        $table->addColumn(Column::string('qr_scene_str',200)->setNullable()->setComment('二维码场景内容'));
        $table->addTimestamps('create_at');
        $table->create();
    }
}
